package com.ruoyi.web.controller.hz;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.system.domain.co.HzUploadInfoCo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HzUploadInfo;
import com.ruoyi.system.service.IHzUploadInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上传总信息Controller
 *
 * @author ruoyi
 * @date 2021-07-17
 */
@Controller
@RequestMapping("/fileUP")
public class HzUploadInfoController extends BaseController {
    private String prefix = "fileUP/info";

    @Autowired
    private IHzUploadInfoService hzUploadInfoService;


    @GetMapping()
    public String info() {
        return prefix + "/info";
    }

    //图片上传页面
    @GetMapping("/index")
    public String index() {
        return "fileUP/index";
    }


    /**
     * 验证上传标题名称是否已经存在
     *
     * @param titleName
     * @return
     */
    @GetMapping("/checkTitleNameUnique")
    @ResponseBody
    public String checkTitleNameUnique(String titleName) {
        return hzUploadInfoService.checkTitleNameUnique(titleName.trim());
    }


    //上传文件
    @Log(title = "上传总信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HzUploadInfoCo fileUpInfo) {
        try {
            return toAjax(hzUploadInfoService.insertHzUploadInfo(fileUpInfo));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toAjax(false);
    }

    /**
     * 查询上传总信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HzUploadInfoCo hzUploadInfo) {
        startPage();
        List<HzUploadInfo> list = hzUploadInfoService.selectHzUploadInfoList(hzUploadInfo);
        return getDataTable(list);
    }

    /**
     * 导出上传总信息列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "上传总信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HzUploadInfo hzUploadInfo) {
        List<HzUploadInfo> list = hzUploadInfoService.selectHzUploadInfoList(hzUploadInfo);
        ExcelUtil<HzUploadInfo> util = new ExcelUtil<HzUploadInfo>(HzUploadInfo.class);
        return util.exportExcel(list, "上传总信息数据");
    }

    /**
     * 修改上传总信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        HzUploadInfo hzUploadInfo = hzUploadInfoService.selectHzUploadInfoById(id);
        mmap.put("hzUploadInfo", hzUploadInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存上传总信息
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "上传总信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HzUploadInfo hzUploadInfo) {
        return toAjax(hzUploadInfoService.updateHzUploadInfo(hzUploadInfo));
    }

    /**
     * 删除上传总信息
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "上传总信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(hzUploadInfoService.deleteHzUploadInfoByIds(ids));
    }
}
